﻿using SD.Toolkits.Mapper;
using SlamDunk.MES.Domain.Entities.ConfigurationContext;
using SlamDunk.MES.IAppService.DTOs.Outputs.ConfigurationContext;
using SlamDunk.MES.IAppService.DTOs.Outputs.FoundationContext;
using SlamDunk.MES.IAppService.DTOs.Outputs.ResourceContext;
using System;
using System.Collections.Generic;

namespace SlamDunk.MES.AppService.Maps
{
    /// <summary>
    /// 配置上下文映射
    /// </summary>
    public static class ConfigurationMap
    {
        #region # 用户扩展映射 —— static UserExtensionInfo ToDTO(this UserExtension userExtension)
        /// <summary>
        /// 用户扩展映射
        /// </summary>
        public static UserExtensionInfo ToDTO(this UserExtension userExtension, IDictionary<Guid, PersonInfo> personInfos, IDictionary<Guid, FacilityInfo> facilityInfos)
        {
            UserExtensionInfo userExtensionInfo = userExtension.Map<UserExtension, UserExtensionInfo>();
            userExtensionInfo.PersonInfo = personInfos?[userExtension.PersonId];
            userExtensionInfo.FacilityInfo = facilityInfos?[userExtension.FacilityId];

            return userExtensionInfo;
        }
        #endregion

        #region # 用户相关储存位置映射 —— static UserRelatedStorageLocationInfo ToDTO(this UserRelatedStorageLocation...
        /// <summary>
        /// 用户相关储存位置映射
        /// </summary>
        public static UserRelatedStorageLocationInfo ToDTO(this UserRelatedStorageLocation relatedStorageLocation)
        {
            UserRelatedStorageLocationInfo relatedStorageLocationInfo = relatedStorageLocation.Map<UserRelatedStorageLocation, UserRelatedStorageLocationInfo>();

            return relatedStorageLocationInfo;
        }
        #endregion

        #region # 终端映射 —— static TerminalInfo ToDTO(this Terminal terminal)
        /// <summary>
        /// 终端映射
        /// </summary>
        public static TerminalInfo ToDTO(this Terminal terminal)
        {
            TerminalInfo terminalInfo = terminal.Map<Terminal, TerminalInfo>();

            return terminalInfo;
        }
        #endregion

        #region # 硬件映射 —— static HardwareInfo ToDTO(this Hardware hardware)
        /// <summary>
        /// 硬件映射
        /// </summary>
        public static HardwareInfo ToDTO(this Hardware hardware)
        {
            HardwareInfo hardwareInfo = hardware.Map<Hardware, HardwareInfo>();
            hardwareInfo.ConnectionInfo = hardware.Connection?.ToDTO();

            return hardwareInfo;
        }
        #endregion

        #region # 硬件连接映射 —— static HardwareConnectionInfo ToDTO(this HardwareConnection connection)
        /// <summary>
        /// 硬件连接映射
        /// </summary>
        public static HardwareConnectionInfo ToDTO(this HardwareConnection connection)
        {
            HardwareConnectionInfo connectionInfo = connection.Map<HardwareConnection, HardwareConnectionInfo>();

            return connectionInfo;
        }
        #endregion

        #region # 工作通知映射 —— static NotificationInfo ToDTO(this Notification notification...
        /// <summary>
        /// 工作通知映射
        /// </summary>
        public static NotificationInfo ToDTO(this Notification notification, IDictionary<Guid, FacilityInfo> facilityInfos)
        {
            NotificationInfo notificationInfo = notification.Map<Notification, NotificationInfo>();
            notificationInfo.FacilityInfo = notification.FacilityId.HasValue
                ? facilityInfos?[notification.FacilityId.Value]
                : null;

            return notificationInfo;
        }
        #endregion
    }
}
